<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="../../component/layui/css/layui.css">
  <script src="../../component/jquery3.6.0.js"></script>

  <style>
    .search_month{
      position:absolute;
      left:170px;
      top: 10px;
    }


  </style>
</head>
<body>
<!-- 内容主体区域 -->
<div style="margin-top: 20px;margin-left: 15px">销售管理>>机会管理</div>

<div class="layui-form">
  <div class="layui-form-item">

    <div class="layui-inline search_month">
      <div class="layui-input-inline">
        <input type="text" class="layui-input" id="search_name" name="search_name" placeholder="请输入机会编码">
      </div>
      <button type="button" class="layui-btn" onclick="reLoad()">查询用户</button>
    </div>

  </div>
</div>
<hr>


<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add_new">添加</button>
  </div>
</script>

<table class="layui-hide" id="test" lay-filter="test"></table>

<!-- 文件导入-->
<script type="text/javascript" src="../../component/layui/layui.js"></script>


<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit" >修改</a>
  <a class="layui-btn layui-btn-xs" lay-event="distribute" >分配</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
</script>

<script>

  var zs_chance_code;
  var zs_chance_name;
  var zs_chance_typename;
  var zs_cm_content;
  var zs_des;
  var zs_chance_id;

  var table_re;
  function reLoad(){
    var search_name=$('#search_name').val();
    console.log(search_name);
    table_re.reload({
      url:'http://localhost:8181/Manager_war/CmServlet/list_search?search_name='+search_name
    });

  }

  layui.use('table', function(){
    var table = layui.table;

    table_re=table.render({
      elem: '#test'
      ,url:'http://localhost:8181/Manager_war/CmServlet/list'
      ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
        title: '提示'
        ,layEvent: 'LAYTABLE_TIPS'
        ,icon: 'layui-icon-tips'
      }]
      ,title: '用户数据表'
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field:'chance_id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
        ,{field:'chance_name', title:'机会名称', width:170}
        ,{field:'chance_typename', title:'机会类型', width:170}
        ,{field:'create_time', title:'录入时间', width:200}
        ,{field:'entry_name', title:'录入人', width:150}
        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:250}
      ]]
      ,page: true
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);
      switch(obj.event){
        case 'add_new':
          layer.open({
            type:2
            ,title:'提交'
            ,area: ['340px','460px']
            ,shadeClose:false
            //,btn:['确定','取消']
            ,content:'chance/add_cm.html'
          });
          //var data = checkStatus.data;
          //layer.alert(JSON.stringify(data));
          break;

              //自定义头工具栏右侧图标 - 提示
        case 'LAYTABLE_TIPS':
          layer.alert('这是工具栏右侧自定义的一个图标按钮');
          break;
      };
    });

    //监听行工具事件
    table.on('tool(test)', function(obj){
      var data = obj.data;
      //console.log(obj)
      if(obj.event === 'del'){
        layer.confirm('真的删除行么', function(index){
          obj.del();
          console.log(data.saleplan_id);
          $.ajax({
            url:'http://localhost:8181/Manager_war/CmServlet/del',
            data:"chance_id="+data.chance_id,
            dataType:'json',
            // contentType:'application/json',form text  请求的格式 给后端是以json格式进行传输
            type:'post',
            success:function(result){
              if(result.code==0){
                layer.msg(result.msg,{icon:1,time:1000},function(){
                  parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                  window.parent.location.reload(true);
                });
              }else{
                layer.msg(result.msg,{icon:2,time:1000});
              }
            }
          });
          layer.close(index);
        });
      }

      else if(obj.event==='detail'){
        zs_chance_code=data.chance_code;
        zs_chance_name=data.chance_name;
        zs_chance_typename=data.chance_typename;
        zs_cm_content=data.cm_content;
        zs_des=data.des;
        layer.open({
          type:2
          ,title:'查看机会管理信息'
          ,area: ['340px','460px']
          ,shadeClose:false
          ,btn:['退出']
          ,content:'chance/detail_cm.html'
        });

      }

      else if(obj.event === 'edit'){

        zs_chance_code=data.chance_code;
        zs_chance_name=data.chance_name;
        zs_chance_typename=data.chance_typename;
        zs_cm_content=data.cm_content;
        zs_des=data.des;
        zs_chance_id=data.chance_id;

        layer.open({
          type:2
          ,title:'修改机会管理信息'
          ,area: ['340px', '570px']
          ,shadeClose:false
          ,content:'chance/modify_cm.html'
        })
      }
      else if(obj.event==='distribute'){
        //layer.confirm('真的要提交吗');
        zs_chance_id=data.chance_id;

        layer.open({
          type:2
          ,title:'分配销售绩效信息'
          ,area: ['340px', '600px']
          ,shadeClose:false
          ,content:'chance/distribute_cm.html'
        })
      }
    });
  });
</script>

</body>
</html>